package thread;

/**
 * 获取线程相关信息的一组方法
 */
public class ThreadInfoDemo {
    public static void main(String[] args) {
        Thread main = Thread.currentThread();//获取主线程
        /*
            获取线程的名字
            如果线程没有指定名字,系统分配的名字为Thread-X   X:是一个数字从0开始
         */
        String name = main.getName();
        System.out.println("名字:"+name);
        //获取唯一标识
        long id = main.getId();
        System.out.println("id:"+id);
        //获取线程的优先级,有10个等级分别用数字1-10表示.1最低,10最高,5是默认值
        int priority = main.getPriority();
        System.out.println("优先级:"+priority);
        //线程是否活着
        boolean isAlive = main.isAlive();
        System.out.println("isAlive:"+isAlive);
        //是否为守护线程
        boolean isDaemon = main.isDaemon();
        System.out.println("isDaemon:"+isDaemon);
        //线程是否被中断
        boolean isInterrupted = main.isInterrupted();
        System.out.println("isInterrupted:"+isInterrupted);

    }
}
